#include <iostream>
using namespace std;
#include <string>

void replace_char1( char a[], int len)
{
	for( int i = 0; i < len; i++)
	{
		if( i == 0)
		{
			a[i] = a[i] - 32;
		}
		if( a[i-1] == 32)
		{
			a[i] = a[i] - 32;
		}
	}
}

string replace_char2(const string &a)
{
	string s = a;
	bool bechange = true;
	for( int i = 0; i < a.length(); i++)
	{
		if (a[i] == 32)
		{
			bechange = true;
		}
		else
		{
			if (bechange) 
			{
				if (a[i] >= 'a' && a[i] <= 'z')
				{
				    s[i] = a[i] - 32;//32 change b ,define a var b = 'a'-'A'.
				}
   	            bechange = false;
				
			}		
		}
	}
    return s;

}

string reverse_sen(const string& str)
{
	string strRes;
	string strWord;
	
	for (size_t i = 0; i < str.length(); i++)
	{
		if (str[i] != ' ')
		{
			strWord.push_back(str[i]);
		}
		else
		{
			if (!strWord.empty())
			{
				strRes.insert(0, strWord);
				strWord.clear();
			}
			strRes.insert(0, 1, ' ');
		}
	}
	
	if (!strWord.empty())
		strRes.insert(0, strWord);
	
	return strRes;
}
void display ( char a[], int len)
{
	for( int i = 0; i < len; i++)
	{
		cout << a[i];
	}
}

int main()
{
    char a[] = {"this a big pig!"};
    char b[] = {" that Is    a pig!"};
    char c[] = {
    	"I love U"
    };
 	int len = sizeof(a)/sizeof(char);
 	replace_char1(a, len);
 	display(a, len);
 	cout << endl;
 	cout << replace_char2(b) << endl;

 	cout << reverse_sen(c) << endl;
    return 0;
}
